import CreateHttp from "./CreateHttp";

export const apiUrl = "http://127.0.0.1:8081";
export const eventApiUrl = "http://127.0.0.1:8081";
//export const apiUrl = "/";


export const defHttp = new CreateHttp({
  apiUrl,
  // urlPrefix: '/api',

  withToken: false,

  // 结果数据格式统一
  transformResponse(data: { code: 0 | 1; msg: string; data: any }) {
    let code: number = data.code;
    switch (code) {
      case 0:
        code = 200;
        break;
    }
    return {
      code,
      message: data.msg,
      result: data.data,
    };
  },
});

export const eventHttp = new CreateHttp({
  apiUrl: eventApiUrl,
  withToken: false,

  // 结果数据格式统一
  transformResponse(data: { result: number; error_msg: string; data: any }) {
    let code: number = data.result;
    switch (code) {
      case 10000:
        code = 200;
        break;
    }
    return {
      code,
      message: data.error_msg,
      result: data,
    };
  },
});
